package com.qf.springboot4;

import com.qf.springboot4.anno.EnablePerson;
import com.qf.springboot4.anno.MyConditionalOnClass;
import com.qf.springboot4.conditions.MyCondition;
import com.qf.springboot4.domain.Person;
import com.qf.springboot4.domain.Student;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication

//开启mapper层接口的包扫描
@MapperScan("com.qf.springboot4.mapper")
//开启事务支持
@EnableTransactionManagement
/**
 * proxyTargetClass 用来控制使用的是jdk代理还是cglib代理
 *  默认值是false，默认使用的是jdk代理，当目标对象没有实现接口时，会采用cglib代理
 *  设置为true，强制使用cglib代理
 */
//@EnableAspectJAutoProxy(proxyTargetClass = false)
//@EnablePerson
public class Springboot4Application {

    public static void main(String[] args) {
        SpringApplication.run(Springboot4Application.class, args);
    }

    @Bean
    //@Conditional(MyCondition.class) //在向spring容器中添加stu对象时，先根据@Conditional配置的条件类进行判断。如果判断为true，添加，否则不添加
    @MyConditionalOnClass(className = "com.qf.springboot4.domain.Person")
    public Student stu(){
        Student stu = new Student();
        stu.setName("zs");
        stu.setAge(18);
        return stu;
    }
}
